package com.travelsky.app.security.manager;


import java.util.List;
import java.util.Set;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.travelsky.app.persistence.Role;
import com.travelsky.app.util.PaginationSupport;

public interface IRoleService {
	
	/**
	 * 根据角色名查找角色是否存在  use hibernate query cache
	 * @param name    角色名
	 * @return ture  存在   false不存在  
	 */
	@Transactional(
			propagation = Propagation.SUPPORTS,   
			isolation = Isolation.DEFAULT 
		)
	public boolean existRoleByName(String name);
	/**
	 * 添加角色
	 *   
	 */
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT ,rollbackFor = Exception.class)
	public void addRole(Role role);
	/**
	 * 根据角色名查找角色是否存在  use hibernate query cache
	 * @param name    角色名 
	 * @return Role   不存在返回null
	 */
	@Transactional(
			propagation = Propagation.SUPPORTS,   
			isolation = Isolation.DEFAULT  
		)
	public Role findRoleByName(String name);
	
	
	/**
	 * 修改角色 
	 * @param existRole  待修改的角色
	 */
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT ,rollbackFor = Exception.class)
	public void modifyRole(Role existRole);
	/**
	 * 根据条件分页查询角色
	 * @param roleListCriteria  查询条件
	 * @param startIndex 起始元素标号
	 * @return PaginationSupport<Role>    
	 */
	@Transactional(
			propagation = Propagation.SUPPORTS,   
			isolation = Isolation.DEFAULT // 锁级别
		)
	public PaginationSupport<Role> findRoleList(DetachedCriteria roleListCriteria, int startIndex);
	
	
	/**
	 * 找出所有角色  use hibernate query cache
	 * @return List<Role>  如果没有则返回空集合
	 */
	@Transactional(propagation = Propagation.SUPPORTS, 
			isolation = Isolation.DEFAULT // 锁级别
	)
	public List<Role> findAllRole();
	/**
	 * 根据角色名字查询出对应的角色 use hibernate query cache
	 * @param roleNames  角色名集合
	 * @return Set<Role> 角色    如果没有则返回空集合
	 */
	@Transactional(propagation = Propagation.SUPPORTS, 
			isolation = Isolation.DEFAULT // 锁级别
	)
	public Set<Role> findRoleByNames(List<String> roleNames);
	
}
